package com.six.firstpage.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.six.core.entity.Link;
import com.six.firstpage.service.LinkService;
import com.six.firstpage.mapper.LinkMapper;
import org.checkerframework.common.value.qual.StaticallyExecutable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author ZZH
* @description 针对表【tb_link】的数据库操作Service实现
* @createDate 2023-02-27 10:21:18
*/
@Service
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link>
    implements LinkService{

    @Autowired
    private LinkMapper linkMapper;

    @Override
    public List<Link> getAllLink() {
        QueryWrapper<Link> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted",0);
        wrapper.eq("is_disable",0);
        List<Link> links = linkMapper.selectList(wrapper);
        return links;
    }

    //查询链接
    @Override
    public Page<Link> getLinkByName(String name, Integer status, Integer current, Integer pageSize) {
        Page<Link> linkPage = new Page<>(current, pageSize);
        QueryWrapper<Link> wrapper = new QueryWrapper<>();
        if (name!=null){
            wrapper.like("link_name",name);
        }
        if (status!=null){
            wrapper.eq("is_disable",status);
        }
        wrapper.eq("is_deleted",0);
        Page<Link> page = linkMapper.selectPage(linkPage, wrapper);

        return page;
    }

    //添加链接
    @Override
    public Integer addLink(Link link) {
        return linkMapper.insert(link);
    }

    //修改链接
    @Override
    public Integer updateLink(Link link) {
        return linkMapper.updateById(link);
    }

    //逻辑删除链接
    @Override
    public Integer delLink(Integer linkId) {

        UpdateWrapper<Link> wrapper = new UpdateWrapper<>();
        wrapper.eq("link_id",linkId);
        wrapper.set("is_deleted",1);
        return linkMapper.update(null,wrapper);
    }
}




